import { combineReducers } from 'redux';
import { persistReducer } from 'redux-persist';
// import storage from 'redux-persist/lib/storage';
import session from 'redux-persist/lib/storage/session';

/**
 * reducer 分开来写
 */
import authReducer from './authReducer';
import counterReducer from './counterReducer';

/**
 * 默认情况下会缓存所有的数据，除非设置黑名单，或者白名单
 */
const rootPersistConfig = {
	key: 'root',
	storage: session,
	// reducer 里不持久化的数据,除此外均为持久化数据 这个auth对应combineReducers中的键
	blacklist: [ 'auth' ]
	// reducer 里持久化的数据,除此外均为不持久化数据
	//   whitelist: ['auth']
};

/**
 * 可以设置不同的配置
 */
// const authPersistConfig = {
// 	key: 'auth',
// 	storage: session
// 	//   blacklist: ['']
// };

const rootReducer = combineReducers({
	// auth: persistReducer(authPersistConfig, authReducer),
	auth: authReducer,
	counter: counterReducer
});

export default persistReducer(rootPersistConfig, rootReducer);
